package com.pai4j.jianlipai.config.configuration;
import com.pai4j.common.config.annotation.ValidateLoginInterceptor;
import com.pai4j.common.config.annotation.RequestPermissionInterceptor;
import com.pai4j.common.config.annotation.SafeClickInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web mvc配置
 *
 * @author: CYM-pai
 * @date: 2025/05/05 13:08
 **/
@Configuration
public class JianLiPaiWebMvcConfigurer implements WebMvcConfigurer {

    /***
     * 注册自定义拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 注册权控拦截器
         */
        registry.addInterceptor(requestPermissionInterceptor()).addPathPatterns("/api/**");
        /**
         * 注册安全点击拦截器
         */
        registry.addInterceptor(safeClickInterceptor()).addPathPatterns("/api/**");
        /**
         * 登录核验
         */
        registry.addInterceptor(validateLoginInterceptor()).addPathPatterns("/api/**");
    }

    /***
     * 权控拦截器 Bean
     * @return
     */
    @Bean
    public RequestPermissionInterceptor requestPermissionInterceptor() {
        return new RequestPermissionInterceptor();
    }

    /***
     * 安全点击拦截器 Bean
     * @return
     */
    @Bean
    public SafeClickInterceptor safeClickInterceptor() {
        return new SafeClickInterceptor();
    }

    /***
     * 校验必须登录
     * @return
     */
    @Bean
    public ValidateLoginInterceptor validateLoginInterceptor() {
        return new ValidateLoginInterceptor();
    }
}